package org.example.controller;


import org.example.common.R;
import org.example.pojo.entity.WmNews;
import org.example.service.IApLoveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-02-04
 */
@CrossOrigin(maxAge = 3600)
@RestController
@RequestMapping("/front/love")
public class ApLoveController {

    @Autowired
    private IApLoveService apLoveService;

    /**
     * 点赞
     *
     * @param articleId
     * @return
     */
    @GetMapping("/like")
    public R like(@RequestParam String articleId) {
       apLoveService.like(articleId);
        return R.ok("点赞成功");

    }

    /**
     * 取消点赞
     *
     * @param articleId
     * @return
     */
    @GetMapping("/unlike")
    public R unlike(@RequestParam String articleId) {
       apLoveService.unlike(articleId);
        return R.ok("取消成功");
    }


    /**
     * 是否点赞
     *
     * @param articleId
     * @return
     */
    @GetMapping("/islike")
    public R islike(@RequestParam String articleId) {
        Long count = apLoveService.islike(articleId);
        return R.ok(count);
    }

    /**
     * 个人喜欢的作品
     */
    @GetMapping("/like/article")
    public R likeArticle() {
        List<WmNews> wmNewsList = apLoveService.likeArticle();
        return R.ok(wmNewsList);
    }
}
